package cn.smbms.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import cn.smbms.pojo.User;
import cn.smbms.util.Constants;

public class SysInterceptor extends HandlerInterceptorAdapter {
	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		User user = (User)request.getSession().getAttribute(Constants.USER_SESSION);
		//拦截的作用：session对象校验
		System.out.println("user=" + user);
		if(user == null) {//没有登录，跳转到登录页面
			response.sendRedirect(request.getContextPath()+"/login");
			return false;
		} else {//显示公共数据
			return true;
		}
	}

}
